# 工具链配置
    CC = riscv64-unknown-elf-gcc
    LD = riscv64-unknown-elf-ld
    OBJCOPY = riscv64-unknown-elf-objcopy

    # 编译选项 - 使用32位架构以匹配参考代码
    CFLAGS = -nostdlib -fno-builtin -Wall -Werror -Iinclude -c \
             -march=rv32i -mabi=ilp32 -g

    # 链接选项
    LDFLAGS = -T kernel/kernel.ld -m elf32lriscv

    # 目标文件
    OBJS = kernel/entry.o \
           kernel/uart.o \
           kernel/kmain.o

    # 默认目标
    all: kernel.elf

    # 链接生成ELF文件
    kernel.elf: $(OBJS)
	    $(LD) $(LDFLAGS) -o $@ $(OBJS)

    # 编译启动代码
    kernel/entry.o: kernel/entry.S
	    $(CC) $(CFLAGS) -o $@ $<

    # 编译UART驱动
    kernel/uart.o: kernel/uart.c include/uart.h include/stdint.h
	     $(CC) $(CFLAGS) -o $@ $<

    # 编译主函数
    kernel/kmain.o: kernel/kmain.c include/uart.h
	    $(CC) $(CFLAGS) -o $@ $<
    # 清理
    clean:
	    rm -f $(OBJS) kernel.elf
    # 运行QEMU
    qemu: kernel.elf
	    qemu-system-riscv32 -machine virt -bios none -kernel kernel.elf -nographic

    .PHONY: all clean qemu